Skip to content

Make Ractor-compatible - #344

Merged
naitoh merged 16 commits into
ruby:masterfrom
jhawthorn:ractors
Sep 6, 2026
Merged

naitoh merged 16 commits into
ruby:masterfrom
jhawthorn:ractors

Conversation

@jhawthorn

Copy link
Copy Markdown
Member

For the most part this just involved freezing Strings or other constants. I tried to aim for the best final state rather than workarounds, so let me know if any changes are desired/anything is too aggressive ❤️. Where possible I changed to frozen_string_literal: true instead of simply freezing the required constants.

Two more significant changes are:

  • Changed FunctionsClass to use method_defined?(x, false) instead of maintaining a mutable hash. This required bumping to Ruby 2.6
  • Changed REXML::Security to use ivars instead of cvars. This module wasn't included anywhere internally so it should work the same. (Ruby 4.1+ will allow cvars to be read from Ractors so this change was only necessary for earlier/current versions, but I think it's faster and better anyways)

@naitoh

naitoh commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@jhawthorn
Thanks for this PR.

This PR does not include tests for Ractor, so please add them.

This required bumping to Ruby 2.6

Previously this was using class variables, however this module isn't
included anywhere, so we might as well just use plain ivars
The @@available_functions class-variable wasn't frozen (to allow
runtime methods to be added). I should be as fast to check for
method_defined?(name, false), though this requires Ruby 2.6
This fixes a FrozenError on Ruby 2.6/2.7. On Ruby 3.0+ interpolated
strings are always unfrozen
@jhawthorn

Copy link
Copy Markdown
Member Author

@naitoh Sorry for the delay!

This has been rebased and I've added a couple tests of Ractors. The Ractor tests only run on Ruby 4.0+, as there are known issues on earlier versions (though the tests should pass as far back as 3.1, they might be flaky)

This _should_ work, but for some reason is hanging (observed on HEAD
w/ windows-latest)
@jhawthorn

Copy link
Copy Markdown
Member Author

This was hanging on windows CI (not sure why, almost certainly an upstream bug we should look into) so I skipped windows with the new tests for now.

@kou kou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@naitoh naitoh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@naitoh
naitoh merged commit dd6d7ca into ruby:master Sep 6, 2026
71 checks passed
@naitoh

naitoh commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Thanks!

julik added a commit to guerilla-di/tracksperanto that referenced this pull request Oct 2, 2026
Importers, exporters and tools no longer depend on anything a non-main
Ractor can't touch:

* The format registries and tool parameters are frozen arrays which
  get replaced on registration instead of mutated
* Casts, Safety, Mux and Crop generate methods from strings instead of
  define_method with a block
* Constants are made shareable via the shareable_constant_value magic
  comment, computed ones get frozen explicitly
* progressive_io 2.x replaces 1.x, which is built on DelegateClass(IO)

test/test_ractor_smoke.rb converts 16 fixtures across all importers,
each in its own Ractor, through the full pipeline with tools and all
exporters, and compares against a main-Ractor run. Ruby 4.0+ only,
since Tempfile.new is unusable from non-main Ractors before that.

REXML comes from git master until the Ractor fix in
ruby/rexml#344 is released.

CI now also runs on Ruby 3.4 and 4.0. Bump to 4.3.0.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
julik added a commit to guerilla-di/tracksperanto that referenced this pull request Oct 5, 2026
* Make Tracksperanto usable from within Ractors

Importers, exporters and tools no longer depend on anything a non-main
Ractor can't touch:

* The format registries and tool parameters are frozen arrays which
  get replaced on registration instead of mutated
* Casts, Safety, Mux and Crop generate methods from strings instead of
  define_method with a block
* Constants are made shareable via the shareable_constant_value magic
  comment, computed ones get frozen explicitly
* progressive_io 2.x replaces 1.x, which is built on DelegateClass(IO)

test/test_ractor_smoke.rb converts 16 fixtures across all importers,
each in its own Ractor, through the full pipeline with tools and all
exporters, and compares against a main-Ractor run. Ruby 4.0+ only,
since Tempfile.new is unusable from non-main Ractors before that.

REXML comes from git master until the Ractor fix in
ruby/rexml#344 is released.

CI now also runs on Ruby 3.4 and 4.0. Bump to 4.3.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Work with frozen string literals

The Shake lexer appends to its atom buffer, which was an empty string
literal - use a mutable buffer instead. All library files get the
frozen_string_literal magic comment, and the two tests which collect
progress messages into string literals use mutable strings.

Require tickly 2.2.1, which fixes the same problem in its parser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Bring the change summary up to date

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Require the released obuf 1.3.1 and flame_channel_parser 4.2.1

These carry the frozen_string_literal changes, so the versions we test
against are the ones we ask for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Update the open items in the change summary

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants